//
//  SRAboutViewController.m
//  SportRing
//
//  Created by icelee on 14-11-1.
//  Copyright (c) 2014年 HotOne. All rights reserved.
//

#import "SRAboutViewController.h"
#import "UIImageView+RoundImage.h"
#import "Utils.h"
#import "SRSystemNetService.h"
#import "SRDB.h"

@interface SRAboutViewController ()

@property (nonatomic, weak)IBOutlet UIImageView *logoImageView;
@property (nonatomic, weak)IBOutlet UILabel *versionLabel;
@property (nonatomic, weak) IBOutlet UILabel * userCountLabel;
@property (nonatomic, strong)NSString * updateUrl;
@end

@implementation SRAboutViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self addBackButton];
    [self setCustomTitle:NSLocalizedString(@"关于", nil)];
    [self setVersion];
    @weakify(self);
    [[SRSystemNetService getMilepost] subscribeNext:^(id x) {
        SRSystem * system = [SRSystem findDefaultSystem];
        self_weak_.userCountLabel.text = [NSString stringWithFormat:@"%@", [system.userCount stringValue]];
    }];
}

- (void)setVersion
{
    self.versionLabel.text = [NSString stringWithFormat:@"V%@",[Utils appVersion]];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self hideTabbar];
    self.navigationController.navigationBarHidden = NO;
    self.edgesForExtendedLayout=UIRectEdgeNone;
}
- (IBAction)guanWangClick:(UIButton *)sender {
    
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.aimoke.cc"]];
}
- (IBAction)updateGengxin:(id)sender {
    [[SRSystemNetService checkVersionUpdate] subscribeNext:^(id x) {
        
        NSDictionary * dict = x;
        NSString * buildVersion = [Utils buildVersion];
        if ([buildVersion isEqualToString:dict[@"version"]]) {
            
            //                [self_weak_ goLogin];
        }
        else
        {
            _updateUrl = dict[@"update_url"];
            
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"更新提示" message:@"有新的版本可以更新啦" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
            
            [alertView show];
            
        }
    } error:^(NSError *error) {
        
        //        [self_weak_ goLogin];
    }];
    [SRSystemNetService getPoster];
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    
    if (buttonIndex == 0)
    {
        return;
        
    }
    if (buttonIndex == 1)
    {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:_updateUrl]];
    }
}

@end
